'''
    Djiscography: A Django-based Discography generator
    Copyright 2010 Martin Paul Eve

    This file is part of Djiscography.

    Djiscography is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.
    
    Djiscography is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
    along with Djiscography.  If not, see <http://www.gnu.org/licenses/>.

'''

from django.db import models

class ReleaseType(models.Model):
    name = models.CharField(blank=True, max_length=500)
    display_order = models.IntegerField(default=0)
    
    def __unicode__(self):
        return str(self.name)
    
    class Meta:
        verbose_name = 'Release Type'
        
class Artist(models.Model):
    name = models.CharField(blank=True, max_length=500)
    biography = models.TextField(blank=True)
    
    def __unicode__(self):
        return self.name

class Release(models.Model):
    name = models.CharField(blank=True, max_length=500)
    artist = models.ForeignKey(Artist)
    year = models.IntegerField(null=True, blank=True)
    type = models.ForeignKey(ReleaseType)
    order = models.IntegerField(null=True, blank=True)
    purchase_link = models.URLField(blank=True)
    
    def __unicode__(self):
        return self.name

class Edition(models.Model):
    name = models.CharField(blank=True, max_length=500)
    release = models.ForeignKey(Release)
    catalogue_number = models.CharField(blank=True, max_length=500)
    record_label = models.CharField(blank=True, max_length=500)
    year = models.IntegerField(null=True, blank=True)
    media = models.CharField(blank=True, max_length=500)
    purchase_link = models.URLField(blank=True)
    
    def __unicode__(self):
        if self.name is None:
            return ''
        return self.release.artist.name + ' - ' + self.release.name + ': ' + self.name + ' [' + self.catalogue_number + ']'
    
class Track(models.Model):
    name = models.CharField(blank=True, max_length=500)
    edition = models.ForeignKey(Edition)
    track_number = models.CharField(null=True, blank=True, max_length=500)
    mix_info = models.CharField(blank=True, max_length=500)
    remixer = models.ForeignKey(Artist)
    length = models.CharField(blank=True, max_length=500)
    sample = models.URLField(blank=True)
    
    def __unicode__(self):
        return str(self.edition) + ': ' + str(self.track_number) + ' - ' + self.name + ' (' + self.mix_info + ')'
    
class Lyric(models.Model):
    track = models.CharField(blank=True, max_length=500)
    lyrics = models.TextField(null=True, blank=True)
    comments = models.TextField(null=True, blank=True)
    
    def __unicode__(self):
        return str(self.track)

class Image(models.Model):
    display_name = models.CharField(blank=True, max_length=500)
    edition = models.ForeignKey(Edition)
    url = models.URLField(blank=True)

    def __unicode__(self):
        return str(self.edition) + ' [' + self.display_name + ']'


